#include "gtest/gtest.h"

#include <memory>
#include "OrderedMessage.h"

using namespace streamdb;


TEST(OrderedMessage, serializable){
    std::cout << "testSerializableOrderedMessage....." << std::endl;

    auto order = std::make_shared<OrderedMessage>(1, "hello");

    std::string bin;
    ASSERT_TRUE(order->toBinary(bin).isOk());
    ASSERT_TRUE(bin == "1:hello");


    auto orderNew = std::make_shared<OrderedMessage>();
    orderNew->fromBinary(bin);
    ASSERT_TRUE(*order == *orderNew);

    {
        auto order = std::make_shared<OrderedMessage>();
        ASSERT_TRUE(orderNew->fromBinary("") == Status::InvalidArgument());
        ASSERT_TRUE(orderNew->fromBinary("123") == Status::InvalidArgument());
        ASSERT_TRUE(orderNew->fromBinary(":") == Status::InvalidArgument());
        ASSERT_TRUE(orderNew->fromBinary(":abc") == Status::InvalidArgument());
        ASSERT_TRUE(orderNew->fromBinary("123:").isOk());
        ASSERT_TRUE(*orderNew == OrderedMessage(123,""));
    }
}
